package cn.xiu.drugstore.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.xiu.drugstore.pojo.Customer;
import cn.xiu.drugstore.service.CustomerService;
import cn.xiu.drugstore.service.impl.CustomerServiceImpl;

public class CustomerServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		String id=request.getParameter("M_Mid");
		String name=request.getParameter("M_Mname");
		String sex=request.getParameter("M_Msex");
		String age=request.getParameter("M_Mage");
		String phone=request.getParameter("M_Mphone");
		String add=request.getParameter("M_Madd");
		Customer cust=new Customer(Integer.valueOf(id),name,sex,Integer.valueOf(age),phone,add);
		CustomerService custService=new CustomerServiceImpl();
		 if(custService.registerCustomer(cust)){
			 out.print("<script>alert('恭喜您，添加成功!');location.href='add_member.jsp';</script>");
	      }else{
	    	  out.print("<script>alert('添加失败!');location.href='add_member.jsp';</script>");
	      }
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);

	}

}
